package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityQueryVO;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_活动管理")
@RequestMapping("/lindi/activity")
public class LindiActivityController{

    @Autowired
    private LindiActivityService service;

    @PostMapping("/addActivity")
    @Operation(summary = "添加活动")
    public R<?> addActivity(@RequestBody @Validated(Add.class) LindiActivityVO activityVO){
        service.addActivity(activityVO);
        return R.ok();
    }

    @DeleteMapping("/deleteActivityByActivityId")
    @Operation(summary = "删除活动 -> 根据活动ID删除")
    public R<?> deleteActivityByActivityId(
            @RequestParam("activityId")
            @NotNull(message = "活动ID不能为空")
            @Parameter(name = "activityId", required = true, description = "活动ID")
            Long activityId){
        service.deleteActivityByActivityId(activityId);
        return R.ok();
    }

    @PutMapping("/updateActivityByActivityId")
    @Operation(summary = "修改活动")
    public R<?> updateActivityByActivityId(
            @RequestBody @Validated(Update.class) LindiActivityVO activityVO){
        service.updateActivityByActivityId(activityVO);
        return R.ok();
    }

    @GetMapping("/getPageActivityList")
    @Operation(summary = "查询活动列表(分页)")
    public R<PageResp<LindiActivityVO>> getPageActivityList(@RequestBody LindiActivityQueryVO queryVO){
        return R.ok(service.getPageActivityList(queryVO));
    }

    @GetMapping("/getActivityByActivityId/{activityId}")
    @Operation(summary = "根据活动ID查询活动")
    public R<LindiActivityVO> getActivityByActivityId(
            @PathVariable(value = "activityId")
            @NotNull(message = "活动ID不能为空")
            @Parameter(name = "activityId", description = "活动ID", required = true)
            Long activityId){
        return R.ok(service.getActivityByActivityId(activityId));
    }
}